package me.ZFC.Text;

import java.util.Scanner;

public class Test19 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串");

        while(true){
            String str = sc.next();
            boolean flag = check(str);
            if(flag){
                break;
            }
            else{
                System.out.println("请重新输入");
            }
        }
    }

    public static boolean check(String s) {
        if (s.length() != 18) {
            return false;
        }
        for (int i = 0; i < s.length() - 1; i++) {
            char c = s.charAt(i);
            if (s.charAt(0) == '0') {
                return false;
            } else if (c < '0' || c > '9') {
                return false;
            }
        }
        if (s.charAt(s.length() - 1) < '0' || s.charAt(s.length() - 1) > '9' && s.charAt(s.length() - 1) != 'X')
            return false;
        return true;
    }
}